package org.lanqiao.controller.collect;

import com.alibaba.dubbo.config.annotation.Reference;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.lanqiao.collect.Collect;
import org.lanqiao.collect.ICollectService;
import org.lanqiao.config.entity.ResponseData;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/collect")
@Api(tags = "收藏贴管理模块Collect")
public class CollectController {
    @Reference
    private ICollectService iCollectService;
    @GetMapping("/CollectList")
    @ApiOperation(value = "查询所有",notes = "无条件查询所有")
    public ResponseData<Collect> CollectList(){
        List<Collect> collectsList = iCollectService.CollectList();
        if(collectsList!= null){
            return  ResponseData.success().putDataVule("collectsList",collectsList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @PostMapping("/AddCollect")
    @ApiOperation(value = "新增收藏贴",notes = "新增一个收藏贴")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "帖子id",name = "cardid",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "帖子收藏者id",name = "userid",required = true,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Collect> AddCollect(Integer cardid, Integer userid){
      Integer result = iCollectService.AddCollect(cardid, userid);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/DeleteCollect")
    @ApiOperation(value = "删除收藏贴",notes = "根据收藏者id删除一个收藏贴")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "帖子id",name = "cardid",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "帖子收藏者id",name = "userid",required = true,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Collect> DeleteCollect(Integer userid,Integer cardid){
        Integer result = iCollectService.DeleteCollect(userid, cardid);
        if(result!= null){
            return  ResponseData.success().putDataVule("result",result);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/SelectByCardid")
    @ApiOperation(value = "查询收藏贴根据card_id",notes = "根据帖子card——id查询收藏贴")
    @ApiImplicitParam(value = "帖子id",name = "cardid",required = true,dataType = "Integer",paramType = "query")
    public ResponseData<Collect> SelectByCardid(Integer cardid){
        List<Collect> collectList = iCollectService.SelectByCardid(cardid);
        if(collectList!= null){
            return  ResponseData.success().putDataVule("collectList",collectList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
    @GetMapping("/SelectByUserid")
    @ApiOperation(value = "查询收藏贴根据user_id",notes = "根据帖子user——id查询收藏贴")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "帖子收藏者id",name = "userid",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "当前页数",name = "pagenum",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(value = "每页显示的条数",name = "pagesize",required = true,dataType = "Integer",paramType = "query")
    })
    public ResponseData<Collect> SelectByUserid(Integer userid, Integer pagenum, Integer pagesize){
        IPage<Collect> collectList = iCollectService.SelectByUserid(userid,pagenum,pagesize);
        if(collectList!= null){
            return  ResponseData.success().putDataVule("collectList",collectList);
        }else{
            return ResponseData.serverInternalError();
        }
    }
}
